package com.sy.webdemo.interceptor;

import com.sy.TransportIPFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author songyi
 * @className HandlerInterceptor
 * @description 拦截器，将ip信息放入RpcContext中
 * @date 2020/8/17 0017 14:14
 */
@Component
public class MyHandlerInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String remoteHost = request.getRemoteHost();
        TransportIPFilter.THREAD_LOCAL.set(remoteHost);
        return true;
    }
}
